package com.ws.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ws.bean.Cat;
import com.ws.bean.User;

public class UserServiceImpl implements IUserService {
	static Map<User, List<Cat>> catDb = new HashMap<User, List<Cat>>() {
		private static final long serialVersionUID = -1736810736725958517L;
		{
			List<Cat> cats = new ArrayList<Cat>();
			cats.add(new Cat(1, "garfield", "橙色"));
			cats.add(new Cat(2, "机器猫", "蓝色"));
			put(new User(1, "sun", "3322", "花果山"), cats);
			cats = new ArrayList<Cat>();
			cats.add(new Cat(3, "cat3", "橙色"));
			cats.add(new Cat(4, "cat4", "蓝色"));
			put(new User(2, "zhu", "5629", "高老庄"), cats);
		}
	};

	public List<Cat> getCatsByUser(User user) {
		return catDb.get(user);
	}

	public Map<String, Cat> getAllCats() {
		HashMap<String, Cat> result = new HashMap<String, Cat>();
		int i = 0;
		for (List<Cat> cats : catDb.values()) {
			for (Cat cat : cats) {
				result.put("第" + (++i) + "个猫", cat);
			}
		}
		return result;
	}

}
